package com.example.sensors;

import java.util.Map;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

import com.example.singletones.contextObj;

public class Sensor_Accelometer extends AbstractSensor implements
		SensorEventListener {
	public static final String NAME = "ACCELOMETER";
	private final SensorManager mSensorManager;
	private Sensor mAccelerometer;

	public Sensor_Accelometer() {
		mSensorManager = (SensorManager) contextObj.getInstance().getmContext()
				.getSystemService(Context.SENSOR_SERVICE);
	}

	public void disableSensor() {
		super.disableSensor();
		mSensorManager.unregisterListener(this);
	}

	public void enableSensor() {
		super.enableSensor();
		mAccelerometer = mSensorManager
				.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
		mSensorManager.registerListener(this, mAccelerometer,
				SensorManager.SENSOR_DELAY_NORMAL);

	}

	public void onAccuracyChanged(Sensor sensor, int accuracy) {
	}

	public void onSensorChanged(SensorEvent event) {
		Map<String, Object> eventArgs = initEventArgs();
		eventArgs.put("eventType", "sensorInfoChanged");
		eventArgs.put("sensorEvent", event);
		OnSensorChanged(eventArgs);
	}

	public String getSensorName() {
		return "Accelometer";
	}
}
